home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDScsiID.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.7 KB  |  138 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDScsiID - An XCMD to open the .AppleCD driver for use by HyperCard.
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/10/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDScsiID.c
  11.     link -sn Main=CDScsiID -sn STDIO=CDScsiID ∂
  12.          -sn INTENV=CDScsiID -rt XFCN=42 ∂
  13.          -m CDScsiID CDScsiID.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"CInterface.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25. #include <SysEqu.h>
  26.  
  27. #define dRAMBased    0x20    /* bit 5 */
  28.  
  29. /* prototype definitions for functions */
  30. OSErr    GetScsiID(short, long *);
  31. Boolean    IsItCD(short);
  32. OSErr    StartAtTrack1(short);
  33. OSErr    AStatus(short, short *);
  34.  
  35. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  36.  
  37.  
  38. /************************************************************************
  39.  *
  40.  *  Function:        CDScsiID
  41.  *
  42.  *  Purpose:        Open the driver and return the ioRefNum
  43.  *
  44.  *  Returns:        ioRefNum (used for subsequent calls to driver)
  45.  *
  46.  *  Side Effects:    none
  47.  *
  48.  *  Description:    We normally don't need any parameters.  Extract the
  49.  *                    vRefNum and pass it to a routine that finds the 
  50.  *                    equivalent SCSI ID.  If we have an invalid vRefNum,
  51.  *                    we return -1 as the SCSI ID, which is invalid.
  52.  *
  53.  ************************************************************************/
  54. pascal void
  55. CDScsiID(paramPtr)
  56. XCmdBlockPtr    paramPtr;
  57. {
  58.     Str31    returnString;
  59.     OSErr    result;
  60.     short    vRefNum;
  61.     long    bothRefNums;
  62.     Handle    refHandle;
  63.     long    scsiID;
  64.     
  65.     /* Must be no parameters */
  66.     if ( paramPtr->paramCount != 0)
  67.     {
  68.         /* Report error in parameters by returning -1 */
  69.         NumToStr(paramPtr, (long) -1, returnString);
  70.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) returnString);
  71.         return;
  72.     }
  73.         
  74.     /* Get the global ioRefNum and convert it. */
  75.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  76.     bothRefNums = atoi(*(refHandle));
  77.     DisposHandle(refHandle);
  78.  
  79.     vRefNum = bothRefNums >> 16;
  80.  
  81.     result = GetScsiID(vRefNum, &scsiID);
  82.     
  83.     NumToStr(paramPtr, scsiID, &returnString);
  84.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  85. }
  86.  
  87.  
  88. /************************************************************************
  89.  *
  90.  *  Function:        GetScsiID
  91.  *
  92.  *  Purpose:        get volume reference number for audio CD
  93.  *
  94.  *  Returns:        OSErr
  95.  *                    noErr if we found an audio volume
  96.  *                    nsvErr if no such volume was mounted
  97.  *                    (may return other errors if problem with system)
  98.  *
  99.  *  Side Effects:    fills in vRefNum
  100.  *
  101.  *  Description:    using the PBHGetVInfo call documented on pages IV-129
  102.  *                    and IV-130 of IM v4, find the dRefNum.  That's the
  103.  *                    offset into the driver table of the driver, and also
  104.  *                    the SCSI ID if you subtract 33.
  105.  *
  106.  *                    0 is normally a valid vRefNum; it means "the system
  107.  *                    volume."  In this case, however, 0 means we haven't
  108.  *                    done a CDOpen yet, or no one is online.  We return
  109.  *                    an error in this case.
  110.  *
  111.  ************************************************************************/
  112. OSErr
  113. GetScsiID(vRefNum, scsiID)
  114. short    vRefNum;        /* volume reference number of volume to use */
  115. long    *scsiID;        /* where to return scsi ID */
  116. {
  117.     OSErr    result;
  118.     HVolumeParam    hParamBlock;
  119.         
  120.     hParamBlock.ioCompletion = 0;
  121.     hParamBlock.ioNamePtr = nil;
  122.     hParamBlock.ioVRefNum = vRefNum;
  123.     hParamBlock.ioVolIndex = 0;
  124.     if (vRefNum == 0)
  125.         result = -1;        /* we don't accept 0 (system) as a valid CD */
  126.     else
  127.         result = PBHGetVInfo(&hParamBlock,false);
  128.  
  129.     if (result == noErr)
  130.         *scsiID = (long)(-hParamBlock.ioVDRefNum) - 32L - 1L;
  131.     else
  132.         *scsiID = -1;         /* an invalid scsiID. */
  133.  
  134.     return result;
  135. }
  136.  
  137. #include <XCmdGlue.inc.c>
  138.